//
//  OrderDetailPriceCell.m
//  danpin
//
//  Created by chuangjia on 29/10/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "OrderDetailPriceCell.h"

@interface OrderDetailPriceCell ()
{
    
}
@property(nonatomic,strong)UILabel *sectionLabel;
@property(nonatomic,strong)UILabel *priceLabel;
@property(nonatomic,strong)UIView *lineview;
//
@property(nonatomic,strong)UIView *line2view;
//
@property(nonatomic,strong)UILabel *ddyfkey;
@property(nonatomic,strong)UILabel *ddyfvalue;

@property(nonatomic,strong)UILabel *gjyfkey;
@property(nonatomic,strong)UILabel *gjyfvalue;

@property(nonatomic,strong)UILabel *ysyfkey;
@property(nonatomic,strong)UILabel *ysyfvalue;

@property(nonatomic,strong)UILabel *hbzhyfkey;
@property(nonatomic,strong)UILabel *hbzhyfvalue;

@property(nonatomic,strong)UILabel *hjspkey;
@property(nonatomic,strong)UILabel *hjspvalue;

@property(nonatomic,strong)UILabel *sfk;
@property(nonatomic,strong)UILabel *xdsj;

@property(nonatomic,strong)UILabel *dkk;
@property(nonatomic,strong)UILabel *dkv;

@property(nonatomic,strong)UILabel *yhk;
@property(nonatomic,strong)UILabel *yhv;
@end
@implementation OrderDetailPriceCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        
        _sectionLabel =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _sectionLabel.backgroundColor = [UIColor clearColor];
        _sectionLabel.textColor = CONTEXT_COLOR;
        _sectionLabel.textAlignment = NSTextAlignmentLeft;
        _sectionLabel.font = FONT(12);
        [self.contentView addSubview:_sectionLabel];
        
        _priceLabel =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _priceLabel.backgroundColor = [UIColor clearColor];
        _priceLabel.textColor =[UIColor blackColor];
        _priceLabel.textAlignment = NSTextAlignmentRight;
        _priceLabel.font = FONT(12);
        [self.contentView addSubview:_priceLabel];
        
        
        _lineview =[[UIView alloc] initWithFrame:CGRectZero];
        _lineview.backgroundColor=UIColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_lineview];
        
        //
        _ddyfkey =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _ddyfkey.backgroundColor = [UIColor clearColor];
        _ddyfkey.textColor = [UIColor darkGrayColor];
        _ddyfkey.textAlignment = NSTextAlignmentLeft;
        _ddyfkey.font = FONT(12);
        [self.contentView addSubview:_ddyfkey];
        
        _ddyfvalue =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _ddyfvalue.backgroundColor = [UIColor clearColor];
        _ddyfvalue.textColor = [UIColor blackColor];
        _ddyfvalue.textAlignment = NSTextAlignmentRight;
        _ddyfvalue.font = FONT(12);
        [self.contentView addSubview:_ddyfvalue];
        
        //
        _gjyfkey =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _gjyfkey.backgroundColor = [UIColor clearColor];
        _gjyfkey.textColor = [UIColor darkGrayColor];
        _gjyfkey.textAlignment = NSTextAlignmentLeft;
        _gjyfkey.font = FONT(12);
        [self.contentView addSubview:_gjyfkey];
        
        _gjyfvalue =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _gjyfvalue.backgroundColor = [UIColor clearColor];
        _gjyfvalue.textColor = [UIColor blackColor];
        _gjyfvalue.textAlignment = NSTextAlignmentRight;
        _gjyfvalue.font = FONT(12);
        [self.contentView addSubview:_gjyfvalue];
        
        //
        _ysyfkey =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _ysyfkey.backgroundColor = [UIColor clearColor];
        _ysyfkey.textColor = [UIColor darkGrayColor];
        _ysyfkey.textAlignment = NSTextAlignmentLeft;
        _ysyfkey.font = FONT(12);
        [self.contentView addSubview:_ysyfkey];
        
        _ysyfvalue =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _ysyfvalue.backgroundColor = [UIColor clearColor];
        _ysyfvalue.textColor = [UIColor blackColor];
        _ysyfvalue.textAlignment = NSTextAlignmentRight;
        _ysyfvalue.font = FONT(12);
        [self.contentView addSubview:_ysyfvalue];
        
        //
        _hbzhyfkey =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _hbzhyfkey.backgroundColor = [UIColor clearColor];
        _hbzhyfkey.textColor =[UIColor darkGrayColor];
        _hbzhyfkey.textAlignment = NSTextAlignmentLeft;
        _hbzhyfkey.font = FONT(12);
        [self.contentView addSubview:_hbzhyfkey];
        
        _hbzhyfvalue =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _hbzhyfvalue.backgroundColor = [UIColor clearColor];
        _hbzhyfvalue.textColor = [UIColor blackColor];
        _hbzhyfvalue.textAlignment = NSTextAlignmentRight;
        _hbzhyfvalue.font = FONT(12);
        [self.contentView addSubview:_hbzhyfvalue];
       
        //
        _dkk =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _dkk.backgroundColor = [UIColor clearColor];
        _dkk.textColor =[UIColor darkGrayColor];
        _dkk.textAlignment = NSTextAlignmentLeft;
        _dkk.font = FONT(12);
        [self.contentView addSubview:_dkk];
        
        _dkv =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _dkv.backgroundColor = [UIColor clearColor];
        _dkv.textColor = [UIColor blackColor];
        _dkv.textAlignment = NSTextAlignmentRight;
        _dkv.font = FONT(12);
        [self.contentView addSubview:_dkv];
        
        //
        _yhk =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _yhk.backgroundColor = [UIColor clearColor];
        _yhk.textColor =[UIColor darkGrayColor];
        _yhk.textAlignment = NSTextAlignmentLeft;
        _yhk.font = FONT(12);
        [self.contentView addSubview:_yhk];
        
        _yhv =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _yhv.backgroundColor = [UIColor clearColor];
        _yhv.textColor = [UIColor blackColor];
        _yhv.textAlignment = NSTextAlignmentRight;
        _yhv.font = FONT(12);
        [self.contentView addSubview:_yhv];
        
        _line2view =[[UIView alloc] initWithFrame:CGRectZero];
        _line2view.backgroundColor=UIColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_line2view];
        
        _sfk =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _sfk.backgroundColor = [UIColor clearColor];
        _sfk.textColor = [UIColor blackColor];
        _sfk.textAlignment = NSTextAlignmentRight;
        _sfk.font = FONT(12);
        [self.contentView addSubview:_sfk];
        
        _xdsj =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH,20)];
        _xdsj.backgroundColor = [UIColor clearColor];
        _xdsj.textColor = [UIColor darkGrayColor];
        _xdsj.textAlignment = NSTextAlignmentRight;
        _xdsj.font = FONT(11);
        [self.contentView addSubview:_xdsj];
        
        
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock =nil;
    self.data=nil;
    self.indexPath=nil;
    self.other=nil;
    self.key=nil;
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key =key;
    self.indexPath=indexPath;
    NSDictionary *dict =(NSDictionary*)model;

    self.data =model;
    //
    
    NSDictionary *order_info =[dict dictionaryObjectForKey:@"order_info"];
    if (order_info==nil || ![order_info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    _sectionLabel.text =@"商品总额";
    _sectionLabel.frame =CGRectMake(PHOTO_FRAME_WIDTH, 0,DEVICE_WIDTH, 40);
    _priceLabel.text =[NSString stringWithFormat:@"¥ %.0f x %d", [[order_info numberStringForKey:@"price"] floatValue], [[order_info numberStringForKey:@"qty"] intValue]];
    _priceLabel.frame =CGRectMake(DEVICE_WIDTH/2-PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH/2, 40);
    _lineview.frame =CGRectMake(PHOTO_FRAME_WIDTH, 39.5,DEVICE_WIDTH, 0.5);
 
    //
    
    _ddyfkey.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*5,DEVICE_WIDTH/2, 20);
    _ddyfvalue.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*5,DEVICE_WIDTH/2, 20);
    _ddyfkey.text = @"当地运费: ";
    _ddyfvalue.text =[NSString stringWithFormat:@"¥ %.0f", [[order_info numberStringForKey:@"shipFeeLocal"] floatValue]];
    //
    _gjyfkey.frame =CGRectMake(PHOTO_FRAME_WIDTH, _ddyfkey.frame.origin.y+_ddyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
    _gjyfvalue.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, _ddyfkey.frame.origin.y+_ddyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);

    NSString *order_productweightunit =[order_info stringForKey:@"weightKg" withDefaultValue:@""];
    _gjyfkey.text =  [NSString stringWithFormat:@"国际运费 (%@): ",order_productweightunit];
    _gjyfvalue.text = [NSString stringWithFormat:@"¥ %.0f", [[order_info numberStringForKey:@"shipFeeOverseas"] floatValue]];
    
    //
    _ysyfkey.frame =CGRectMake(PHOTO_FRAME_WIDTH, _gjyfkey.frame.origin.y+_gjyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
    _ysyfvalue.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, _gjyfkey.frame.origin.y+_gjyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
    _ysyfkey.text = @"预收关税 (多退少补): ";
    _ysyfvalue.text =[NSString stringWithFormat:@"¥ %.0f", [[order_info numberStringForKey:@"taxPrice"] floatValue]];
    //
    _hbzhyfkey.frame =CGRectMake(PHOTO_FRAME_WIDTH, _ysyfkey.frame.origin.y+_ysyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
    _hbzhyfvalue.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, _ysyfkey.frame.origin.y+_ysyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
    _hbzhyfkey.text = @"货币转换费: ";
    
    _hbzhyfvalue.text =[NSString stringWithFormat:@"¥ %.0f",[[order_info numberStringForKey:@"conversionFee"] floatValue]];
    //
    CGFloat fpt = 0;
    CGFloat total_fee =[[dict numberStringForKey:@"total_fee"] floatValue];
    if ([[dict allKeys] containsObject:@"dk_type"])
    {
        NSString *dk_type = [dict stringForKey:@"dk_type" withDefaultValue:@""];
        if (dk_type.length>0)
        {
            int dkkk = [[dict objectForKey:@"dk_type"] intValue];
            if (dkkk==1 || dkkk ==2)
            {
                _dkk.frame =CGRectMake(PHOTO_FRAME_WIDTH, _hbzhyfkey.frame.origin.y+_hbzhyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
                _dkv.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, _hbzhyfkey.frame.origin.y+_hbzhyfkey.frame.size.height+PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
                if (dkkk==1) {
                    _dkk.text = @"积分抵扣: ";
                }else if (dkkk==2)
                {
                    _dkk.text = @"余额抵扣: ";
                }
                _dkv.text =[NSString stringWithFormat:@"- ¥ %.0f",[[dict numberStringForKey:@"dk_fee"] floatValue]];
                fpt =PHOTO_FRAME_WIDTH*19;
            }else{
                fpt =PHOTO_FRAME_WIDTH*16;
            }
        }else{
             fpt =PHOTO_FRAME_WIDTH*16;
        }
       
    }else{
        fpt =PHOTO_FRAME_WIDTH*16;
    }
    
    if ([[dict allKeys] containsObject:@"code_fee"]) {
        NSString *dk_type =[dict stringForKey:@"code_fee" withDefaultValue:@""];
        if (dk_type.length>0) {
            
            _yhk.frame =CGRectMake(PHOTO_FRAME_WIDTH, fpt-PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
            _yhv.frame =CGRectMake(DEVICE_WIDTH - DEVICE_WIDTH/2 -PHOTO_FRAME_WIDTH, fpt-PHOTO_TIME_PADDING,DEVICE_WIDTH/2, 20);
            _yhk.text = @"优惠券抵扣: ";
            _yhv.text =[NSString stringWithFormat:@"- ¥ %.0f",[dk_type floatValue]];
            
            fpt = fpt +PHOTO_FRAME_WIDTH*2.5;
        }
        
    }
    //
    _line2view.frame =CGRectMake(PHOTO_FRAME_WIDTH, fpt,DEVICE_WIDTH, 0.5);
    
    _sfk.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH+fpt,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 20);
    _sfk.text =[NSString stringWithFormat:@"实付款: ¥ %.0f", total_fee];
    _xdsj.frame =CGRectMake(PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*3+fpt,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 20);
    
    NSString *add_time = [[NSString stringWithFormat:@"%@",[dict objectForKey:@"add_time"]] replaceNullString];
    _xdsj.text =[NSString stringWithFormat:@"下单时间: %@", add_time ];
    [self layoutSubviews];
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)clickHelpEvent:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    NSString *str =[NSString stringWithFormat:@"%ld",(long)btn.tag];
    if (self.actionBlock) {
        self.actionBlock(BEventType_help,nil,self.data,str,self.indexPath);
    }
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    CGFloat hight =PHOTO_FRAME_WIDTH*22;
    NSDictionary *dict =(NSDictionary*)model;
    if ([[dict allKeys] containsObject:@"dk_type"]) {
        NSString *dk_type =[dict stringForKey:@"dk_type" withDefaultValue:@""];
        if (dk_type.length>0) {
            int dkkk = [dk_type intValue];
            if (dkkk==1 || dkkk ==2)
            {
                hight = hight + PHOTO_FRAME_WIDTH*3;
                
            }
        }
        
    }
    if ([[dict allKeys] containsObject:@"code_fee"]) {
        NSString *dk_type =[dict stringForKey:@"code_fee" withDefaultValue:@""];
        if (dk_type.length>0) {
            hight = hight + PHOTO_FRAME_WIDTH*2;
        }
        
    }
    
    return hight;
}


@end
